<template>
	<view class="index1_content">
		<view class="search-header">
			<view @click="handeleTo">
				<image style="width: 15rpx;height: 30rpx;" src="@/static/index2/index7.png" mode=""></image>
			</view>
			<view style="color: #FFFFFF;font-size: 32rpx;margin-right: 10rpx;">{{$t('仓库管理')}}</view>
			<view></view>
		</view>

		<view class="search">
			<image style="width: 30rpx;height: 30rpx;" src="@/static/index2/index6.png" mode=""></image>
			<u-input style="margin-left: 12rpx;font-size: 24rpx;" clearable :placeholder="$t('请输入想要搜索的内容')"
				:border="border" v-model="keyword" placeholderStyle="font-size: 24rpx;"></u-input>
			<div class="search-btn" @click="getData(true)">{{$t("搜索")}}</div>
		</view>

		<scroll-view :scroll-top="scrollTop" scroll-y="true" class="scroll-Ys" refresher-enabled="true"
			:refresher-triggered="freshIsShow" @scrolltolower="lower" @refresherrefresh="fresh"
			@refresherrestore="store"
			refresher-background="background: linear-gradient(90deg, #5695FF -2%, #44D1D4 105%);">
			<view v-for="(item,index) in arr" :key="index">
				<!-- codeType 启用禁用状态 -->
				<view :class="!item.status?'WarehouseCode':'WarehouseCode-class'">
					<view class="WarehouseCode1">
						<view style="color: #745343;">{{$t('仓库编码')}}：{{String(item.id).padStart(5,"0")}}</view>
						<view class="WarehouseCode2" @click="changeStatus(item)">{{item.status?$t('禁用'):$t('启用')}}
						</view>
					</view>
					<view class="WarehouseCode3">
						<view style="color: #1D1D1D;font-size: 28rpx;padding: 0 30rpx;">{{$t('仓库名称')}}：
							{{lang==='zh'?item.name:item.name_ru}}
						</view>
						<view style="border-top: 1px dashed #D8D8D8;margin-top: 20rpx;"></view>
						<view style="color: #1D1D1D;font-size: 24rpx;padding: 0 30rpx;margin-top: 24rpx;">
							{{$t('更新时间')}}：{{item.create_at}}
						</view>
						<view style="color: #9E9E9E;font-size: 24rpx;margin-top: 20rpx;padding: 0 30rpx;display: flex;">
							<view style="min-width: 60rpx;">{{$t('备注')}}:</view>
							<view>
								{{lang==='zh'?item.remark:item.remark_ru}}
							</view>
						</view>
						<view style="border-top: 1px dashed #D8D8D8;margin-top: 24rpx;"></view>
						<view class="WarehouseCode4">
							<view class="WarehouseCode51" @click="handelRemove(item,index)">{{$t('删除')}}</view>
							<view class="WarehouseCode52" @click="handeleEdit(item)">{{$t('编辑')}}</view>
							<view class="WarehouseCode53" @click="handeleLocation(item)">{{$t('货位管理')}}</view>
						</view>
					</view>
				</view>
			</view>

			<view v-if="nomore" class="nomore">
				<view>{{$t("没有更多了")}}</view>
			</view>
		</scroll-view>
		<view class="addCk">
			<view class="addCk-but" @click="handeleNew">{{$t('新增仓库')}}</view>
		</view>
		<!-- 顶部背景色 -->
		<image style="width: 750rpx;height: 690rpx;position: absolute;top: 0;z-index: 1;"
			src="@/static/index2/20241101130857.png" mode=""></image>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				nomore: false,
				lang: uni.getStorageSync("lang"),
				border: false,
				keyword: '',
				codeType: false,
				scrollTop: 0, //高度
				freshIsShow: true, //下拉加载
				page: 1, //页数
				total: 0, //总条数
				arr: [], //数据
			}
		},
		onShow() {
			this.getData(true)
		},
		methods: {
			getData(init) {
				if (init) {
					this.page = 1
					this.arr = [];
					this.nomore = false
				}
				this.$u.api.basic.warehouse({
					user_id: uni.getStorageSync("user_id"),
					keyword: this.keyword,
					page: this.page
				}).then(res => {
					if (res.length === 0) {
						this.nomore = true
					}
					if (this.page == 1) {
						this.arr = res;
					} else {
						this.arr = [...this.arr, ...res]
					}
					this.freshIsShow = false
				})
			},
			// 删除
			handelRemove(item, index) {
				uni.showModal({
					title: this.$t('确认删除'),
					content: this.$t('是否确认删除当前文件'),
					confirmText: this.$t('确认'),
					cancelText: this.$t('取消'),
					success: res => {
						if (res.confirm) {
							//调删除接口
							this.$u.api.basic.warehouseDel({
								id: item.id
							}).then(res => {
								uni.showToast({
									title: this.$t("操作成功")
								})
								this.arr.splice(index, 1)
							})
						}
					}
				});
			},
			// 新增
			handeleNew() {
				uni.navigateTo({
					url: '/pages/tabbar/order/newWarehouse?type=' + 'add'
				})
			},
			// 编辑
			handeleEdit(item) {
				uni.navigateTo({
					url: '/pages/tabbar/order/newWarehouse?item=' + JSON.stringify(item)
				})
			},
			// 变更状态
			changeStatus(item) {
				this.$u.api.basic.warehouseSave({
					user_id: uni.getStorageSync("user_id"),
					id: item.id,
					status: item.status ? 0 : 1,
					flag: 1
				}).then(res => {
					uni.showToast({
						title: res.create_at ? this.$t("操作成功") : this.$t("操作失败"),
						icon: res.create_at ? "success" : "error"
					})
					if (res.create_at) {
						item.status = item.status ? 0 : 1
					}
				})
			},
			// 返回上一页
			handeleTo() {
				uni.navigateBack()
			},
			// 下拉刷新复位
			store() {
				this.freshIsShow = false
			},
			// 下拉刷新触发
			fresh() {
				this.freshIsShow = true
				this.getData(true)
			},
			// 触底加载
			lower() {
				// 触底判断总条数不等于当前数据的条数则获取数据
				if (this.total != this.arr.length) {
					this.page++
					this.getData()
				}
			},
			// 货位管理
			handeleLocation(item) {
				uni.navigateTo({
					url: `/pages/tabbar/order/locationOfGoods?w_id=${item.id}&warehouse=${item.name}`
				})
			}
		}
	}
</script>

<style scoped>
	.nomore {
		color: #999;
		font-size: 26rpx;
		text-align: center;
		display: flex;
		align-items: center;
		justify-content: center;

		view {
			background: #f1f2f4;
			border-radius: 30rpx;
			padding: 10rpx
		}
	}

	.addCk-but {
		width: 540rpx;
		height: 90rpx;
		border-radius: 90rpx;
		background: #5282E6;
		color: #FFFFFF;
		font-size: 28rpx;
		text-align: center;
		line-height: 90rpx;
	}

	.addCk {
		width: 100%;
		height: 110rpx;
		background-color: #F1F2F4;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.scroll-Ys {
		margin-top: 24rpx;
		z-index: 2;
		width: 690rpx;
		height: calc(100vh - 380rpx);
	}

	.search-header {
		z-index: 2;
		width: 690rpx;
		height: 133rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;
		margin-top: 40rpx;
	}

	.WarehouseCode9 {
		width: 196rpx;
		height: 60rpx;
		border-radius: 60rpx;
		text-align: center;
		line-height: 60rpx;
		background: #FF5D5D;
		color: #FFFFFF;
		margin-right: 21rpx;
	}

	.WarehouseCode10 {
		width: 196rpx;
		height: 60rpx;
		border-radius: 60rpx;
		text-align: center;
		line-height: 60rpx;
		background: #5282E6;
		color: #FFFFFF;
	}

	.WarehouseCode8 {
		margin-top: 20rpx;
		width: 100%;
		height: 60rpx;
		display: flex;
		align-items: center;
		justify-content: flex-end;
		padding: 0 30rpx;

	}

	.WarehouseCode7 {
		padding: 30rpx 0;
		z-index: 2;
		width: 690rpx;
		min-height: 222rpx;
		border-radius: 32rpx;
		background: #FFFFFF;
		margin-bottom: 24rpx;
	}

	.WarehouseCode51 {
		width: 196rpx;
		height: 60rpx;
		border-radius: 60rpx;
		background: #FF5D5D;
		color: #FFFFFF;
		font-size: 22rpx;
		text-align: center;
		line-height: 60rpx;
	}

	.WarehouseCode52 {
		width: 196rpx;
		height: 60rpx;
		border-radius: 60rpx;
		background: #5282E6;
		color: #FFFFFF;
		font-size: 22rpx;
		text-align: center;
		line-height: 60rpx;
	}

	.WarehouseCode53 {
		width: 196rpx;
		height: 60rpx;
		border-radius: 60rpx;
		background: #06C36E;
		color: #FFFFFF;
		font-size: 22rpx;
		text-align: center;
		line-height: 60rpx;
	}

	.WarehouseCode4 {
		margin-top: 20rpx;
		width: 100%;
		height: 60rpx;
		padding: 0 30rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;
	}

	.WarehouseCode3 {
		width: 100%;
		min-height: 286rpx;
		border-radius: 32rpx;
		background: #FFFFFF;
		padding: 22rpx 0rpx 20rpx 0rpx;
	}

	.WarehouseCode2 {
		width: 133rpx;
		min-height: 48rpx;
		border-radius: 48rpx;
		background: #FFFFFF;
		color: #745343;
		font-size: 22rpx;
		text-align: center;
		line-height: 48rpx;
	}

	.WarehouseCode1 {
		width: 100%;
		height: 72rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;
		font-size: 24rpx;
		padding: 0 30rpx;
		box-sizing: border-box;
	}

	.WarehouseCode {
		margin-bottom: 30rpx;
		z-index: 2;
		width: 690rpx;
		min-height: 358rpx;
		border-radius: 32rpx;
		display: flex;
		flex-direction: column;
		justify-content: space-between;
		background: linear-gradient(91deg, #FCF9E8 0%, #F2C376 95%), linear-gradient(90deg, #CCD6FF -2%, #4A70FC 105%);
	}

	.WarehouseCode-class {
		margin-bottom: 30rpx;
		z-index: 2;
		width: 690rpx;
		min-height: 358rpx;
		border-radius: 32rpx;
		display: flex;
		flex-direction: column;
		justify-content: space-between;
		background: linear-gradient(90deg, #CCD6FF -2%, #4A70FC 105%);
	}

	.search {

		z-index: 2;
		width: 690rpx;
		height: 70rpx;
		background-color: #FFFFFF;
		/* margin-top: 40rpx; */
		border-radius: 12rpx;
		padding: 0 30rpx;
		box-sizing: border-box;
		display: flex;
		align-items: center;
	}

	.search-btn {
		font-size: 26rpx;
		background-color: #5282e6;
		color: #fff;
		border-radius: 10rpx;
		height: 80%;
		display: flex;
		align-items: center;
		justify-content: center;
		width: 120rpx;
		margin-right: -20rpx;
		margin-left: 15rpx;
	}

	.index1_content {
		width: 100%;
		display: flex;
		flex-direction: column;
		align-items: center;
		background-color: #F1F2F4;
		/* height: 100vh; */
	}

	page {
		width: 100%;
		height: 100%;
	}
</style>